//
//  CoreSurface_Dummy.m
//  MobileDoom
//
//  Created by Steven Troughton-Smith on 21/08/2008.
//  Copyright 2008 Steven Troughton-Smith. All rights reserved.
//

#import "iPhoneOSBuild.h"
#import "CoreSurface.h"

#if 1

unsigned long *screen;

CGImageRef screenImage;
CGDataProviderRef provider;


extern CFStringRef kCoreSurfaceBufferGlobal = @"";
extern CFStringRef kCoreSurfaceBufferMemoryRegion  = @"";
extern CFStringRef kCoreSurfaceBufferPitch = @"";
extern CFStringRef kCoreSurfaceBufferWidth = @"";
extern CFStringRef kCoreSurfaceBufferHeight = @"";
extern CFStringRef kCoreSurfaceBufferPixelFormat = @"";
extern CFStringRef kCoreSurfaceBufferAllocSize = @"";


unsigned hightable[256], lowtable[256];
void gentables()
{
	for (int i = 0; i < 256; i++)
	{
		// low byte
		int red = (int)((i & 31) * 255.f / 31.f);
		int lowgreen = (int)(((i >> 5) & 7) * 255.f / 63.f);
		lowtable[i] = red | (lowgreen << 8);
		
		// high byte
		int highgreen = (int)(((i & 7) << 3) * 255.f / 63.f);
		int blue = (int)((i >> 3) * 255.f / 31.f);
		hightable[i] = (blue << 16) | (highgreen << 8);
	}
}

unsigned convert_rgb565_to_rgb888(unsigned short rgb565)
{
	return hightable[rgb565 >> 8] + lowtable[rgb565 & 255];
}

CoreSurfaceBufferRef CoreSurfaceBufferCreate(CFDictionaryRef dict)
{
	int delta = 4;
	
	int size = doom_resolution_width*doom_resolution_height;

	
	screen   = (unsigned char*)malloc(delta *size);
	provider = CGDataProviderCreateWithData(NULL, screen,  delta *size, NULL);	
	
	unsigned char *c;		 
	c = screen; 
	int i;		 
	for (i=0; i<(delta*doom_resolution_width*doom_resolution_height); i++) {		 
		*c++ = 0;		 
	}	

	
	screenImage = CGImageCreate(	
								doom_resolution_width,
								doom_resolution_height,
								8, // bpc
								32, // bpp
								4 * doom_resolution_width, // bpr
								CGColorSpaceCreateDeviceRGB(),
								kCGBitmapByteOrder16Host,
								provider,
								NULL,
								NO,
								kCGRenderingIntentDefault
								);
	
	CGImageRetain(screenImage);
	
	return screenImage;
}

int CoreSurfaceBufferLock(CoreSurfaceBufferRef surface, unsigned int lockType)
{
}

int CoreSurfaceBufferUnlock(CoreSurfaceBufferRef surface)
{
}

void *CoreSurfaceBufferGetBaseAddress(CoreSurfaceBufferRef surface)
{
}


#endif